#include "CMessageSystem.h"

CMessageSystem* CMessageSystem::GetInstance( void )
{
	static CMessageSystem msgSYS;
	return &msgSYS;
}
void CMessageSystem::InitMessageSystem( MESSAGEPROC pfnMsgProc )
{
	if( !pfnMsgProc )
		return;

	m_pfnMsgProc = pfnMsgProc;
}
void CMessageSystem::SendMsg( CMessager* msg )
{
	if( !msg )
		return ;

	m_MsgQueue.push( msg );

}
void CMessageSystem::ProcessMessages( void )
{
	if( !this->m_pfnMsgProc )
		return ;

	while( !m_MsgQueue.empty() )
	{
		 m_pfnMsgProc( m_MsgQueue.front()  );
		 delete m_MsgQueue.front();
		 m_MsgQueue.pop();
	}
}
void CMessageSystem::ClearAllMessages( void )
{
	while( !m_MsgQueue.empty() )
	{
		delete m_MsgQueue.front();
		m_MsgQueue.pop();
	}
}
void CMessageSystem::ShutdownMessageSystem( void )
{
	ClearAllMessages();
	m_pfnMsgProc = NULL;
}